package torres.item;
import java.io.Serializable;
import java.util.*;

/**
 * @author Torres
 * Represents an Entity's inventory. 
 * Maintains a list of items (up to a maximum number).
 * Allows for addition/removal of items. 
 * 
 */
@SuppressWarnings("serial")
public class Inventory  implements Serializable
{
	private int maxSize;
	private int currSize;
	private List<TakeableItem> itemList; 
	
	/**
	 * Creates an Inventory that can hold 15 items.
	 */
	public Inventory() {
		
		maxSize = 15;
		currSize = 0;
		itemList = new ArrayList<TakeableItem>(maxSize);
	}
	
	
	/**
	 * Add the specified item to the inventory.
	 * @param The item to be added to the inventory.
	 * @return True if the item was successfully added, false otherwise.
	 */
	public boolean addItem(TakeableItem item) {
		boolean ret = true;
		
		if(!this.isFull()) {
			this.getItemList().add(item);
			++currSize;
		}
		else
			ret = false;
		return ret;
	}
	
	
	/**
	 * Remove the specified item from the inventory.
	 * @param The item to be removed from the inventory
	 * @return The Item that was removed if successful, null otherwise.
	 */
	public TakeableItem removeItem(TakeableItem item) {
		
		TakeableItem ret = null;
		int index = this.getItemList().indexOf(item);
		if(index != -1)
		{
			ret = this.getItemList().get(index);
			this.getItemList().remove(item);
			--currSize;
		}
		
		return ret;
	}
	
	/**
	 * Returns a List of Items representing the Inventory.
	 * @return A List of Items representing the Inventory
	 */
	public List<TakeableItem> getItemList() {
		
		return this.itemList;
	}
	
	/**
	 * Retrieves the item at the specified index.
	 * @param index The index of the item to be retrieved.
	 * @return The item at the specified index if it exists, null otherwise.
	 */
	public Item getItem(int index) {
		return itemList.get(index);
	}
	
	/**
	 * Returns the current size (number of items) of the Inventory.
	 * @return The current number of items in the inventory.
	 */
	public int getCurrentSize() {
		
		return this.currSize;
	}
	
	/**
	 * Returns the total capacity of the Inventory.
	 * @return The maximum number of items that can be added to the inventory.
	 */
	public int getMaxSize() {
		
		return this.maxSize;
	}
	
	/**
	 * Tests to see if the inventory is full. 
	 * @return True if the number of items in the inventory is the maximum number of items, false otherwise.
	 */
	public boolean isFull()
	{
		return (maxSize == currSize);
	}
	
	/**
	 * Tests to see if the specified item is in the inventory.
	 * @param item The item to be checked.
	 * @return True if the item is in the inventory, false otherwise.
	 */
	public boolean hasItem(TakeableItem item) {
		return this.getItemList().contains(item);
	}
}
